<?php
// +----------------------------------------------------------------------
// | @filename AdminUserController.php
// +----------------------------------------------------------------------
// | @author 落花轻舞问君愁 <mwcx1990@qq.com>
// +----------------------------------------------------------------------
// | @datetime 2021-10-28 12:19:37
// +----------------------------------------------------------------------
// | @Description
// +----------------------------------------------------------------------

namespace Addons\Backend\Http\Controllers;

use Addons\Backend\Http\Requests\AdminUser\AssignRolesRequest;
use Addons\Backend\Http\Requests\AdminUser\CreateAdminUserRequest;
use Addons\Backend\Http\Requests\AdminUser\UpdateAdminUserRequest;
use Addons\Backend\Logics\AdminUserLogic;
use Illuminate\Http\Request;

class AdminUserController extends BaseController
{
    protected $adminUserLogic;

    public function __construct(AdminUserLogic $adminUserLogic)
    {
        $this->adminUserLogic = $adminUserLogic;
    }

    /**
     * 管理员列表
     * @param Request $request
     * @return mixed
     */
    public function list(Request $request)
    {
        $res = $this->adminUserLogic->list($request->input());
        return $this->respond($res);
    }

    /**
     * 管理员信息
     * @return mixed
     */
    public function info()
    {
        $res = $this->adminUserLogic->info();
        return $this->respond($res);
    }

    /**
     * 创建管理员
     * @param CreateAdminUserRequest $request
     * @return mixed
     */
    public function create(CreateAdminUserRequest $request)
    {
        $res = $this->adminUserLogic->create($request->validated());
        return $this->respond($res);
    }

    /**
     * 编辑管理员
     * @param UpdateAdminUserRequest $request
     * @return mixed
     */
    public function update(UpdateAdminUserRequest $request)
    {
        $res = $this->adminUserLogic->update($request->validated());
        return $this->respond($res);
    }

    /**
     * 删除管理员
     * @param $id
     * @return mixed
     */
    public function delete($id)
    {
        $res = $this->adminUserLogic->delete($id);
        return $this->respond($res);
    }

    /**
     * 给管理员分配角色
     * @param AssignRolesRequest $request
     * @return mixed
     */
    public function assignRoles(AssignRolesRequest $request)
    {
        $res = $this->adminUserLogic->assignRoles($request->validated());
        return $this->respond($res);
    }

    /**
     * 获取管理员已授权的菜单
     * @param Request $request
     * @return mixed
     */
    public function getUserMenus(Request $request){
        $res = $this->adminUserLogic->getUserMenus($request->get('userId'));
        return $this->respond($res);
    }

    /**
     * 获取管理员已授权的角色
     * @param Request $request
     * @return mixed
     */
    public function getUserRoles(Request $request){
        $res = $this->adminUserLogic->getUserRoles($request->get('userId'));
        return $this->respond($res);
    }
}
